{% extends "base/front.html" %}

{% block title %}Interest Blog Index | SaintIC{% endblock %}

{% if g.plugins.BaiduStatistics %}
{% block head %}
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?88f6d909dd0d8f80bb9748f43ade3ac7";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>
{% endblock %}
{% endif %}

{% block content %}

  <div class="home">
    <h1 class="page-heading">
        <a href="{{ url_for('.index', tab='all') }}" title="所有文章">所有文章</a><span class="badge green" id="index_number"></span>&nbsp;
        <a href="{{ url_for('.index', tab='update') }}" title="最近十篇更新文章">最近更新</a><span class="badge yellow" id="update_number"></span>&nbsp;
        <a href="{{ url_for('.index', tab='hot') }}" title="最新十篇热评文章">热评文章</a><span class="badge red" id="hot_number"></span>&nbsp;
        <!--<a href="{{ url_for('.index', tab='top') }}" title="所有置顶文章">所有置顶</a><span class="badge blue" id="top_number"></span>&nbsp;-->
        <a href="{{ url_for('.index', tab='recommend') }}" title="所有推荐文章">所有推荐</a><span class="badge purple" id="recommend_number"></span>&nbsp;
    </h1>
    <hr /><br />
    <ul class="post-list" id="article_service_top">
    </ul>
    <ul class="post-list" id="article">
      <!--
      <li>
        <span class="post-meta">Jan 1, 2016</span>
        <h2>
          <a class="post-link" href="/blog">固定文章索引</a>
        </h2>
      </li>
      -->
    </ul>
  </div>

{% if g.plugins["ChristmasBlessings"] in ("true", "True", True) %}
  <!--圣诞节祝福插件-->
  <div id="MagicFace" style="position: absolute; z-index: 999;">
  <script src="http://qiniu.ws234.com/christmas.js"></script>
</div>
{% endif %}

{% endblock %}

{% block script %}
    <script type="text/javascript">
        // 获取所有文章索引
        $.ajax({
            url: "{{ g.apiurl }}/blog?get_index_only=true&sort=desc&limit=all",
            method: 'GET',
            datatype: 'json',
            success: function(res) {
                console.log(res);
                var data= res.data;
                var str = '';
                document.getElementById('index_number').innerHTML=data.length;
                for(i=0; i<data.length; i++) {
                    blog = data[i];
                    str += '<li><span class="post-meta">' + blog.create_time + '</span><h2><a class="post-link" href="/blog/' + blog.id + '.html">' + blog.title + '</a></h2></li>';
                };
                {%- if request.args.get("tab", "all") == "all" %}
                document.getElementById('article').innerHTML=str;
                console.log("index all");
                {% endif %}
            },
            error: function(error){
                console.log(error);
                alert("所有文章数据获取错误，请尝试刷新重试！");
            }
        });
        // 获取10篇更新文章索引
        $.ajax({
            url: "{{ g.apiurl }}/blog?get_update_data=true&sort=desc&limit=10",
            method: 'GET',
            datatype: 'json',
            success: function(res) {
                console.log(res);
                var data= res.data;
                var str = '';
                document.getElementById('update_number').innerHTML=data.length;
                for(i=0; i<data.length; i++) {
                    blog = data[i];
                    str += '<li><span class="post-meta">' + blog.update_time + '</span><h2><a class="post-link" href="/blog/' + blog.id + '.html">' + blog.title + '</a></h2></li>';
                };
                {%- if request.args.get("tab", "all") == "update" %}
                document.getElementById('article').innerHTML=str;
                console.log("index update");
                {% endif %}
            },
            error: function(error){
                console.log(error);
                alert("最近更新数据获取错误，请尝试刷新重试！");
            }
        });
        // 获取10篇热评文章索引
        $.ajax({
            url: "{{ url_for('api.ApiComments') }}",
            method: 'GET',
            datatype: 'json',
            success: function(res) {
                console.log(res);
                var data= res.data;
                var str = '';
                document.getElementById('hot_number').innerHTML=data.length;
                for(i=0; i<data.length; i++) {
                    blog = data[i];
                    str += '<li><b class="post-meta badge red">热评</b>&nbsp;<span class="post-meta">' + blog.created_at + '</span><h2><a class="post-link" href="' + blog.url + '">' + blog.title + '</a></h2></li>';
                    /*
                    if (i==0) {
                      {%- if request.args.get("tab", "all") == "all" %}
                        document.getElementById('article_service_hot').innerHTML=str;
                      {% endif -%}
                    }
                    */
                };
                {%- if request.args.get("tab", "all") == "hot" %}
                document.getElementById('article').innerHTML=str;
                console.log("index hot");
                {% endif %}
            },
            error: function(error){
                console.log(error);
                alert("热评文章数据获取错误，请尝试刷新重试！");
            }
        });
        // 获取所有置顶文章索引
        $.ajax({
            url: "{{ g.apiurl }}/blog?get_top_data=true&sort=desc&limit=all",
            method: 'GET',
            datatype: 'json',
            success: function(res) {
                console.log(res);
                var data= res.data;
                var str = '';
                //document.getElementById('top_number').innerHTML=data.length;
                for(i=0; i<data.length; i++) {
                    blog = data[i];
                    str += '<li><b class="post-meta badge blue">置顶</b>&nbsp;<span class="post-meta">' + blog.update_time + '</span><h2><a class="post-link" href="/blog/' + blog.id + '.html">' + blog.title + '</a></h2></li>';
                    /*
                    if (i==0) {
                      {%- if request.args.get("tab", "all") == "all" %}
                        document.getElementById('article_service_top').innerHTML=str;
                      {% endif -%}
                    }
                    */
                };
                {%- if request.args.get("tab", "all") == "all" %}
                //document.getElementById('article').innerHTML=str;
                console.log("index top");
                document.getElementById('article_service_top').innerHTML=str;
                {% endif %}
            },
            error: function(error){
                console.log(error);
                alert("置顶文章数据获取错误，请尝试刷新重试！");
            }
        });
        // 获取所有推荐文章索引
        $.ajax({
            url: "{{ g.apiurl }}/blog?get_recommend_data=true&sort=desc&limit=all",
            method: 'GET',
            datatype: 'json',
            success: function(res) {
                console.log(res);
                var data= res.data;
                var str = '';
                document.getElementById('recommend_number').innerHTML=data.length;
                for(i=0; i<data.length; i++) {
                    blog = data[i];
                    str += '<li><b class="post-meta badge purple">推荐</b>&nbsp;<span class="post-meta">' + blog.update_time + '</span><h2><a class="post-link" href="/blog/' + blog.id + '.html">' + blog.title + '</a></h2></li>';
                    /*
                    if (i==0) {
                      {%- if request.args.get("tab", "all") == "all" %}
                        document.getElementById('article_service_recommend').innerHTML=str;
                      {% endif -%}
                    }
                    */
                };
                {%- if request.args.get("tab", "all") == "recommend" %}
                document.getElementById('article').innerHTML=str;
                console.log("index recommend");
                {% endif %}
            },
            error: function(error){
                console.log(error);
                alert("推荐文章数据获取错误，请尝试刷新重试！");
            }
        });
    </script>
{% endblock %}
